<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="设备Id" prop="deviceId">-->
<!--        <el-input-->
<!--          v-model="queryParams.deviceId"-->
<!--          placeholder="请输入设备Id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="车牌号" prop="deviceNo">
        <el-input
          v-model="queryParams.carNo"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="sim卡号" prop="simNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.simNum"-->
<!--          placeholder="请输入sim卡号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="车辆Id" prop="carId">-->
<!--        <el-input-->
<!--          v-model="queryParams.carId"-->
<!--          placeholder="请输入车辆Id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wx:vehiclelog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wx:vehiclelog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="vehiclelogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="日志id" align="center" prop="vehicleLogId" v-if="columns[0].visible"/>
      <el-table-column label="设备Id" align="center" prop="deviceId" v-if="columns[1].visible"/>
      <el-table-column label="设备号" align="center" prop="deviceNo" v-if="columns[2].visible"/>
      <el-table-column label="sim卡号" align="center" prop="simNo" v-if="columns[3].visible"/>
      <el-table-column label="车辆Id" align="center" prop="carId" v-if="columns[4].visible"/>
      <el-table-column label="车牌号" align="center" prop="carNo" v-if="columns[5].visible"/>
<!--      <el-table-column label="司机Id" align="center" prop="personId" v-if="columns[6].visible"/>-->
      <el-table-column label="司机姓名" align="center" prop="personName" v-if="columns[7].visible"/>
      <el-table-column label="分组Id" align="center" prop="groupId" v-if="columns[8].visible"/>
      <el-table-column label="分组名称" align="center" prop="groupName" v-if="columns[9].visible"/>
      <el-table-column label="数据端口号" align="center" prop="devicePort" v-if="columns[10].visible"/>
      <el-table-column label="经度" align="center" prop="x" v-if="columns[11].visible"/>
      <el-table-column label="纬度" align="center" prop="y" v-if="columns[12].visible"/>
      <el-table-column label="速度" align="center" prop="speed" v-if="columns[13].visible"/>
      <el-table-column label="里程" align="center" prop="mileage" v-if="columns[14].visible"/>
<!--      <el-table-column label="油针值" align="center" prop="oilNeedle" v-if="columns[15].visible"/>-->
<!--      <el-table-column label="油量" align="center" prop="oilVolumn" v-if="columns[16].visible"/>-->
      <el-table-column label="方向" align="center" prop="direction" v-if="columns[17].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_direction" :value="scope.row.direction"/>
        </template>
      </el-table-column>
      <el-table-column label="方向度数" align="center" prop="directionDegree" v-if="columns[18].visible"/>
      <el-table-column label="GPS信号标记" align="center" prop="flag" v-if="columns[19].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_have_no" :value="scope.row.flag"/>
        </template>
      </el-table-column>
      <el-table-column label="发动机状态" align="center" prop="accStatus" v-if="columns[20].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_open_close" :value="scope.row.accStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="车门状态" align="center" prop="doorStatus" v-if="columns[21].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_open_close" :value="scope.row.doorStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="后尾箱状态" align="center" prop="weightStatus" v-if="columns[22].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_open_close" :value="scope.row.weightStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="寻求信息状态" align="center" prop="seekStatus" v-if="columns[23].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_is_not" :value="scope.row.seekStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否空载" align="center" prop="isNoLoad" v-if="columns[24].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_is_not" :value="scope.row.isNoLoad"/>
        </template>
      </el-table-column>
      <el-table-column label="是否设防" align="center" prop="isFortification" v-if="columns[25].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_is_not" :value="scope.row.isFortification"/>
        </template>
      </el-table-column>
      <el-table-column label="实时状态" align="center" prop="realTimeStatus" v-if="columns[26].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.common_vehicle_status" :value="scope.row.realTimeStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="状态时长" align="center" prop="statusDuration" v-if="columns[27].visible"/>
      <el-table-column label="车内温度" align="center" prop="temperature" v-if="columns[28].visible"/>
      <el-table-column label="总脉冲里程" align="center" prop="pulseOdo" v-if="columns[29].visible"/>
<!--      <el-table-column label="总脉冲数" align="center" prop="pulseCount" v-if="columns[30].visible"/>-->
<!--      <el-table-column label="脉冲速度" align="center" prop="pulseSpeed" v-if="columns[31].visible"/>-->
<!--      <el-table-column label="基站局号" align="center" prop="gsmloc" v-if="columns[32].visible"/>-->
<!--      <el-table-column label="基站蜂窝号" align="center" prop="gsmci" v-if="columns[33].visible"/>-->
<!--      <el-table-column label="国家代号" align="center" prop="accuracy" v-if="columns[34].visible"/>-->
<!--      <el-table-column label="事件代码" align="center" prop="eventCode" v-if="columns[35].visible"/>-->
      <el-table-column label="事件说明" align="center" prop="eventDesc" v-if="columns[36].visible"/>
      <el-table-column label="报警类型列表" align="center" prop="alarmLists" v-if="columns[37].visible"/>
<!--      <el-table-column label="车辆原始状态信息" align="center" prop="carStatus" v-if="columns[38].visible"/>-->
      <el-table-column label="gps定位时间" align="center" prop="gpsTime" width="180" v-if="columns[39].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gpsTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column >
      <el-table-column label="上报时间" align="center" prop="reportTime" width="180" v-if="columns[40].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.reportTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" v-if="columns[41].visible">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="columns[42].visible">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['wx:vehiclelog:edit']"-->
<!--          >修改</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wx:vehiclelog:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
  import {getVehiclelog, listVehiclelog,addVehiclelog,updateVehiclelog,delVehiclelog,getCurrentLocation} from "@/api/wx/vehiclelog";

  export default {
    name: "Vehiclelog",
    dicts:['common_have_no','common_is_not','common_open_close','common_direction','common_vehicle_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆日志表格数据
      vehiclelogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceId: null,
        deviceNo: null,
        simNum: null,
        carId: null,
        carNo: null,
        personId: null,
        personName: null,
        groupId: null,
        groupName: null,
        devicePort: null,
        x: null,
        y: null,
        speed: null,
        mileage: null,
        oilNeedle: null,
        oilVolumn: null,
        direction: null,
        directionDegree: null,
        flag: null,
        accStatus: null,
        doorStatus: null,
        weightStatus: null,
        seekStatus: null,
        isNoLoad: null,
        isFortification: null,
        realTimeStatus: null,
        statusDuration: null,
        temperature: null,
        pulseOdo: null,
        pulseCount: null,
        pulseSpeed: null,
        gsmloc: null,
        gsmci: null,
        accuracy: null,
        eventCode: null,
        eventDesc: null,
        alarmList: null,
        carStatus: null,
        gpsTime: null,
        reportTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },

      cardIdList:[],
      columns:[
        {key:'0',label:'日志id',visible:'true'},
        {key:'1',label:'设备id',visible:'true'},
        {key:'2',label:'设备号',visible:'true'},
        {key:'3',label:'sim卡号',visible:'true'},
        {key:'4',label:'车辆id',visible:'true'},
        {key:'5',label:'车牌号',visible:'true'},
        {key:'6',label:'司机id',visible:'false'},
        {key:'7',label:'司机姓名',visible:'true'},
        {key:'8',label:'分组id',visible:'true'},
        {key:'9',label:'分组名称',visible:'true'},
        {key:'10',label:'数据端口号',visible:'true'},
        {key:'11',label:'经度',visible:'true'},
        {key:'12',label:'纬度',visible:'true'},
        {key:'13',label:'速度',visible:'true'},
        {key:'14',label:'里程（km）',visible:'true'},
        {key:'15',label:'油针值',visible:'true'},
        {key:'16',label:'油量（升）',visible:'true'},
        {key:'17',label:'方向',visible:'true'},
        {key:'18',label:'方向度数',visible:'true'},
        {key:'19',label:'GPS信号标记',visible:'true'},
        {key:'20',label:'发动机状态',visible:'true'},
        {key:'21',label:'车门状态',visible:'true'},
        {key:'22',label:'后尾箱状态',visible:'true'},
        {key:'23',label:'寻求信息状态',visible:'true'},
        {key:'24',label:'是否空载',visible:'true'},
        {key:'25',label:'是否设防',visible:'true'},
        {key:'26',label:'实时状态',visible:'true'},
        {key:'27',label:'状态时长',visible:'true'},
        {key:'28',label:'车内温度',visible:'true'},
        {key:'29',label:'总脉冲里程',visible:'true'},
        {key:'30',label:'总脉冲数',visible:'true'},
        {key:'31',label:'脉冲速度',visible:'true'},
        {key:'32',label:'基站局号',visible:'false'},
        {key:'33',label:'基站蜂窝号',visible:'false'},
        {key:'34',label:'国家代号',visible:'false'},
        {key:'35',label:'事件代码',visible:'false'},
        {key:'36',label:'事件说明',visible:'true'},
        {key:'37',label:'报警类型列表',visible:'true'},
        {key:'38',label:'车辆原始状态信息',visible:'false'},
        {key:'39',label:'GPS定位时间',visible:'true'},
        {key:'40',label:'上报时间',visible:'true'},
        {key:'41',label:'创建时间',visible:'true'},
        {key:'42',label:'操作',visible:'true'},
      ]
    };
  },
  created() {
    let carId;
    var url=decodeURI(window.location.search); //获取url中"?"符后的字串
    if(url.indexOf("?") !== -1) {
      carId = url.substr(url.indexOf("=")+1);
    }
    console.log("window.location.showSearch",window.location.search.carId)
    this.cardIdList.push(carId)
    this.getList();
  },
  methods: {
    /** 查询车辆日志列表 */
    getList() {
      this.loading = true;
      listVehiclelog(this.queryParams).then(response => {
        this.vehiclelogList = response.rows;
        console.log(this.vehiclelogList)
        this.total = response.total;
        this.loading = false;
      });

      // getCurrentLocation(this.cardIdList).then(res=>{
      //   if (res.data.code == 200){
      //     console.log("=====res=====",res)
      //     this.vehiclelogList = res.data.data;
      //     this.loading = false;
      //     this.vehiclelogList.forEach(item=>{
      //       console.log("========item==========",item)
      //       addVehiclelog(JSON.stringify(item))
      //     })
      //   }
      // })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        vehicleLogId: null,
        deviceId: null,
        deviceNo: null,
        simNum: null,
        carId: null,
        carNo: null,
        personId: null,
        personName: null,
        groupId: null,
        groupName: null,
        devicePort: null,
        x: null,
        y: null,
        speed: null,
        mileage: null,
        oilNeedle: null,
        oilVolumn: null,
        direction: null,
        directionDegree: null,
        flag: null,
        accStatus: "0",
        doorStatus: "0",
        weightStatus: "0",
        seekStatus: "0",
        isNoLoad: null,
        isFortification: null,
        realTimeStatus: "0",
        statusDuration: null,
        temperature: null,
        pulseOdo: null,
        pulseCount: null,
        pulseSpeed: null,
        gsmloc: null,
        gsmci: null,
        accuracy: null,
        eventCode: null,
        eventDesc: null,
        alarmList: null,
        carStatus: "0",
        gpsTime: null,
        reportTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.vehicleLogId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const vehicleLogId = row.vehicleLogId || this.ids
      getVehiclelog(vehicleLogId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车辆日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.vehicleLogId != null) {
            updateVehiclelog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVehiclelog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const vehicleLogIds = row.vehicleLogId || this.ids;
      this.$modal.confirm('是否确认删除车辆日志编号为"' + vehicleLogIds + '"的数据项？').then(function() {
        return delVehiclelog(vehicleLogIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wx/vehiclelog/export', {
        ...this.queryParams
      }, `vehiclelog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
